package labox.innovation.gameserver.model;

import java.util.Calendar;

import labox.innovation.gameserver.model.actor.instance.FuzePcInstance;
import labox.innovation.gameserver.model.base.FriendNewsType;

/**
 * @author ljsh
 * @date 2010-4-1
 * @version 1.0
 * @description 关于好友动态消息的数据结构
 */
public class FriendsNews {
	
	private static final StringBuilder buffer = new StringBuilder();

	private FriendNewsType type;

	private String content;

	private FuzePcInstance active;

	public FriendsNews(FuzePcInstance player, FuzePcInstance target, L2ItemInstance item, FriendNewsType type) {
		if (player == null)
			return;
		active = player;
		Calendar ins = Calendar.getInstance();
		buffer.setLength(0);
		buffer.append(ins.get(Calendar.YEAR)).append('-').append(ins.get(Calendar.MONTH) + 1).append('-').append(ins.get(Calendar.DATE));
		buffer.append("<a cmd='' value='").append(player.getObjectId()).append("' >").append(player.getName()).append("</a>");
		this.type = type;
		switch (type) {
		case FRIENDLOGIN:
			login(player);
			break;
		case ADDNEWFRIEND:
			killedAndAddFriends(target, type);
			break;
		case COVERFRIEND:
			upLevelAndDAMO(type);
			break;
		case DAMO:
			upLevelAndDAMO(type);
			break;
		case GROUPIE:
			group(item, type);
			break;
		case KILLED:
			killedAndAddFriends(target, type);
			break;
		case UPLEVEL:
			upLevelAndDAMO(type);
			break;
		default:
			break;
		}
		content = buffer.toString();
	}

	public FriendNewsType getType() {
		return type;
	}

	public void setType(FriendNewsType type) {
		this.type = type;
	}

	public String getContent() {
		return content;
	}

	public FuzePcInstance getActive() {
		return active;
	}

	private void killedAndAddFriends(FuzePcInstance target, FriendNewsType type) {
		if (type == FriendNewsType.ADDNEWFRIEND) {
			buffer.append("将<a cmd='' val='").append(target.getObjectId()).append("' >").append(target.getName()).append("</a>加为好友!");
		}
		if (type == FriendNewsType.KILLED) {
			buffer.append("被<a cmd='' val='").append( target.getObjectId()).append("' >").append( target.getName()).append("</a>杀害!");
		}
	}

	private void upLevelAndDAMO(FriendNewsType type) {
		if (type == FriendNewsType.DAMO) {
			buffer.append("渡劫飞升至").append(active.getPracticeId().getId() ).append("!");
		}
		if (type == FriendNewsType.UPLEVEL) {
			buffer.append("修炼至").append(active.getLevel()).append("级!");
		}
		if (type == FriendNewsType.COVERFRIEND) {
			buffer.append("将我加为好友!");
		}
	}

	private void group(L2ItemInstance item, FriendNewsType type) {
		buffer.append("打造出六星").append("(" + item.getName() + ")!");
	}

	private void login(FuzePcInstance player) {
		buffer.append(player.getName());
		buffer.append("上线了！");
	}
}
